package com.lhj.jpa.future;

import java.util.Random;

/**
 * @author linghaijin781
 * @date 2021/9/258:09 下午
 */
public class _03_interrupt {

	public static void main(String[] args) {
		Thread car2 = new Thread(() -> {
			SmallTool.printTimeAndThread("奔驰准备过桥");
			SmallTool.printTimeAndThread("宝马正在过桥，等待");

			try {
				Thread.sleep(3000);
			} catch (InterruptedException e) {

				SmallTool.printTimeAndThread("奔驰开始过桥");
			}

			SmallTool.printTimeAndThread("奔驰过桥了");

		});

		Thread car1 = new Thread(() -> {
			SmallTool.printTimeAndThread("宝马开始过桥");
			int timeSpend = new Random().nextInt(500)+1000;
			SmallTool.sleepMills(timeSpend);
			SmallTool.printTimeAndThread("宝马过桥了，耗时："+ timeSpend);

			car2.interrupt();
		});

		car1.start();
		car2.start();
	}

}
